package com.lujieni.springbootmybatis.consts;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import java.util.Objects;

/**
 * @Author：Jie Ni
 * @Date: 2025/11/14 11:12
 * @Description:
 */
@Getter
public enum MsgTypeEnum {

    EDUCTION("1", "教育"),

    FINANCE("2", "财经");

    @EnumValue
    private final String code;

    private final String desc;

    MsgTypeEnum(String code, String desc){
        this.code = code;
        this.desc = desc;
    }

    // 序列化时返回code
    @JsonValue
    public String getCode() {
        return this.code;
    }

    // 反序列化时调用此方法
    @JsonCreator
    public static MsgTypeEnum fromCode(String code) {
        for (MsgTypeEnum status : values()) {
            if (Objects.equals(status.getCode(), code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid code: " + code);
    }

}
